from enum import Enum

class BlendShapes52(Enum):
    BrowDownLeft = 0
    BrowDownRight = 1
    BrowInnerUp = 2
    BrowOuterUpLeft = 3
    BrowOuterUpRight = 4
    CheekPuff = 5
    CheekSquintLeft = 6
    CheekSquintRight = 7
    EyeBlinkLeft = 8
    EyeBlinkRight = 9
    EyeLookDownLeft = 10
    EyeLookDownRight = 11
    EyeLookInLeft = 12
    EyeLookInRight = 13
    EyeLookOutLeft = 14
    EyeLookOutRight = 15
    EyeLookUpLeft = 16
    EyeLookUpRight = 17
    EyeSquintLeft = 18
    EyeSquintRight = 19
    EyeWideLeft = 20
    EyeWideRight = 21
    JawForward = 22
    JawLeft = 23
    JawOpen = 24
    JawRight = 25
    MouthClose = 26
    MouthDimpleLeft = 27
    MouthDimpleRight = 28
    MouthFrownLeft = 29
    MouthFrownRight = 30
    MouthFunnel = 31
    MouthLeft = 32
    MouthLowerDownLeft = 33
    MouthLowerDownRight = 34
    MouthPressLeft = 35
    MouthPressRight = 36
    MouthPucker = 37
    MouthRight = 38
    MouthRollLower = 39
    MouthRollUpper = 40
    MouthShrugLower = 41
    MouthShrugUpper = 42
    MouthSmileLeft = 43
    MouthSmileRight = 44
    MouthStretchLeft = 45
    MouthStretchRight = 46
    MouthUpperUpLeft = 47
    MouthUpperUpRight = 48
    NoseSneerLeft = 49
    NoseSneerRight = 50
    TongueOut = 51

class BlendShapes61(Enum):
    # Eye movements - Left
    EYE_BLINK_LEFT = 0
    EYE_LOOK_DOWN_LEFT = 1
    EYE_LOOK_IN_LEFT = 2
    EYE_LOOK_OUT_LEFT = 3
    EYE_LOOK_UP_LEFT = 4
    EYE_SQUINT_LEFT = 5
    EYE_WIDE_LEFT = 6

    # Eye movements - Right
    EYE_BLINK_RIGHT = 7
    EYE_LOOK_DOWN_RIGHT = 8
    EYE_LOOK_IN_RIGHT = 9
    EYE_LOOK_OUT_RIGHT = 10
    EYE_LOOK_UP_RIGHT = 11
    EYE_SQUINT_RIGHT = 12
    EYE_WIDE_RIGHT = 13

    # Jaw movements
    JAW_FORWARD = 14
    JAW_RIGHT = 15
    JAW_LEFT = 16
    JAW_OPEN = 17

    # Mouth movements
    MOUTH_CLOSE = 18
    MOUTH_FUNNEL = 19
    MOUTH_PUCKER = 20
    MOUTH_RIGHT = 21
    MOUTH_LEFT = 22
    MOUTH_SMILE_LEFT = 23
    MOUTH_SMILE_RIGHT = 24
    MOUTH_FROWN_LEFT = 25
    MOUTH_FROWN_RIGHT = 26
    MOUTH_DIMPLE_LEFT = 27
    MOUTH_DIMPLE_RIGHT = 28
    MOUTH_STRETCH_LEFT = 29
    MOUTH_STRETCH_RIGHT = 30
    MOUTH_ROLL_LOWER = 31
    MOUTH_ROLL_UPPER = 32
    MOUTH_SHRUG_LOWER = 33
    MOUTH_SHRUG_UPPER = 34
    MOUTH_PRESS_LEFT = 35
    MOUTH_PRESS_RIGHT = 36
    MOUTH_LOWER_DOWN_LEFT = 37
    MOUTH_LOWER_DOWN_RIGHT = 38
    MOUTH_UPPER_UP_LEFT = 39
    MOUTH_UPPER_UP_RIGHT = 40

    # Brow and Cheek movements
    BROW_DOWN_LEFT = 41
    BROW_DOWN_RIGHT = 42
    BROW_INNER_UP = 43
    BROW_OUTER_UP_LEFT = 44
    BROW_OUTER_UP_RIGHT = 45
    CHEEK_PUFF = 46
    CHEEK_SQUINT_LEFT = 47
    CHEEK_SQUINT_RIGHT = 48

    # Nose and Tongue
    NOSE_SNEER_LEFT = 49
    NOSE_SNEER_RIGHT = 50
    TONGUE_OUT = 51

    # Head and Eye Rotation
    HEAD_YAW = 52
    HEAD_PITCH = 53
    HEAD_ROLL = 54
    LEFT_EYE_YAW = 55
    LEFT_EYE_PITCH = 56
    LEFT_EYE_ROLL = 57
    RIGHT_EYE_YAW = 58
    RIGHT_EYE_PITCH = 59
    RIGHT_EYE_ROLL = 60


mapping_61_to_52 = {
    # Eye movements - Left
    BlendShapes61.EYE_BLINK_LEFT.value: BlendShapes52.EyeBlinkLeft.value,
    BlendShapes61.EYE_LOOK_DOWN_LEFT.value: BlendShapes52.EyeLookDownLeft.value,
    BlendShapes61.EYE_LOOK_IN_LEFT.value: BlendShapes52.EyeLookInLeft.value,
    BlendShapes61.EYE_LOOK_OUT_LEFT.value: BlendShapes52.EyeLookOutLeft.value,
    BlendShapes61.EYE_LOOK_UP_LEFT.value: BlendShapes52.EyeLookUpLeft.value,
    BlendShapes61.EYE_SQUINT_LEFT.value: BlendShapes52.EyeSquintLeft.value,
    BlendShapes61.EYE_WIDE_LEFT.value: BlendShapes52.EyeWideLeft.value,

    # Eye movements - Right
    BlendShapes61.EYE_BLINK_RIGHT.value: BlendShapes52.EyeBlinkRight.value,
    BlendShapes61.EYE_LOOK_DOWN_RIGHT.value: BlendShapes52.EyeLookDownRight.value,
    BlendShapes61.EYE_LOOK_IN_RIGHT.value: BlendShapes52.EyeLookInRight.value,
    BlendShapes61.EYE_LOOK_OUT_RIGHT.value: BlendShapes52.EyeLookOutRight.value,
    BlendShapes61.EYE_LOOK_UP_RIGHT.value: BlendShapes52.EyeLookUpRight.value,
    BlendShapes61.EYE_SQUINT_RIGHT.value: BlendShapes52.EyeSquintRight.value,
    BlendShapes61.EYE_WIDE_RIGHT.value: BlendShapes52.EyeWideRight.value,

    # Jaw movements
    BlendShapes61.JAW_FORWARD.value: BlendShapes52.JawForward.value,
    BlendShapes61.JAW_RIGHT.value: BlendShapes52.JawRight.value,
    BlendShapes61.JAW_LEFT.value: BlendShapes52.JawLeft.value,
    BlendShapes61.JAW_OPEN.value: BlendShapes52.JawOpen.value,

    # Mouth movements
    BlendShapes61.MOUTH_CLOSE.value: BlendShapes52.MouthClose.value,
    BlendShapes61.MOUTH_FUNNEL.value: BlendShapes52.MouthFunnel.value,
    BlendShapes61.MOUTH_PUCKER.value: BlendShapes52.MouthPucker.value,
    BlendShapes61.MOUTH_RIGHT.value: BlendShapes52.MouthRight.value,
    BlendShapes61.MOUTH_LEFT.value: BlendShapes52.MouthLeft.value,
    BlendShapes61.MOUTH_SMILE_LEFT.value: BlendShapes52.MouthSmileLeft.value,
    BlendShapes61.MOUTH_SMILE_RIGHT.value: BlendShapes52.MouthSmileRight.value,
    BlendShapes61.MOUTH_FROWN_LEFT.value: BlendShapes52.MouthFrownLeft.value,
    BlendShapes61.MOUTH_FROWN_RIGHT.value: BlendShapes52.MouthFrownRight.value,
    BlendShapes61.MOUTH_DIMPLE_LEFT.value: BlendShapes52.MouthDimpleLeft.value,
    BlendShapes61.MOUTH_DIMPLE_RIGHT.value: BlendShapes52.MouthDimpleRight.value,
    BlendShapes61.MOUTH_STRETCH_LEFT.value: BlendShapes52.MouthStretchLeft.value,
    BlendShapes61.MOUTH_STRETCH_RIGHT.value: BlendShapes52.MouthStretchRight.value,
    BlendShapes61.MOUTH_ROLL_LOWER.value: BlendShapes52.MouthRollLower.value,
    BlendShapes61.MOUTH_ROLL_UPPER.value: BlendShapes52.MouthRollUpper.value,
    BlendShapes61.MOUTH_SHRUG_LOWER.value: BlendShapes52.MouthShrugLower.value,
    BlendShapes61.MOUTH_SHRUG_UPPER.value: BlendShapes52.MouthShrugUpper.value,
    BlendShapes61.MOUTH_PRESS_LEFT.value: BlendShapes52.MouthPressLeft.value,
    BlendShapes61.MOUTH_PRESS_RIGHT.value: BlendShapes52.MouthPressRight.value,
    BlendShapes61.MOUTH_LOWER_DOWN_LEFT.value: BlendShapes52.MouthLowerDownLeft.value,
    BlendShapes61.MOUTH_LOWER_DOWN_RIGHT.value: BlendShapes52.MouthLowerDownRight.value,
    BlendShapes61.MOUTH_UPPER_UP_LEFT.value: BlendShapes52.MouthUpperUpLeft.value,
    BlendShapes61.MOUTH_UPPER_UP_RIGHT.value: BlendShapes52.MouthUpperUpRight.value,

    # Brow and Cheek movements
    BlendShapes61.BROW_DOWN_LEFT.value: BlendShapes52.BrowDownLeft.value,
    BlendShapes61.BROW_DOWN_RIGHT.value: BlendShapes52.BrowDownRight.value,
    BlendShapes61.BROW_INNER_UP.value: BlendShapes52.BrowInnerUp.value,
    BlendShapes61.BROW_OUTER_UP_LEFT.value: BlendShapes52.BrowOuterUpLeft.value,
    BlendShapes61.BROW_OUTER_UP_RIGHT.value: BlendShapes52.BrowOuterUpRight.value,
    BlendShapes61.CHEEK_PUFF.value: BlendShapes52.CheekPuff.value,
    BlendShapes61.CHEEK_SQUINT_LEFT.value: BlendShapes52.CheekSquintLeft.value,
    BlendShapes61.CHEEK_SQUINT_RIGHT.value: BlendShapes52.CheekSquintRight.value,

    # Nose and Tongue
    BlendShapes61.NOSE_SNEER_LEFT.value: BlendShapes52.NoseSneerLeft.value,
    BlendShapes61.NOSE_SNEER_RIGHT.value: BlendShapes52.NoseSneerRight.value,
    BlendShapes61.TONGUE_OUT.value: BlendShapes52.TongueOut.value,
}
 
mapping_52_to_61 = {
      # Eye movements - Left
        BlendShapes52.EyeBlinkLeft.value: BlendShapes61.EYE_BLINK_LEFT.value,  # 8 -> 0
        BlendShapes52.EyeLookDownLeft.value: BlendShapes61.EYE_LOOK_DOWN_LEFT.value,  # 10 -> 1
        BlendShapes52.EyeLookInLeft.value: BlendShapes61.EYE_LOOK_IN_LEFT.value,  # 12 -> 2
        BlendShapes52.EyeLookOutLeft.value: BlendShapes61.EYE_LOOK_OUT_LEFT.value,  # 14 -> 3
        BlendShapes52.EyeLookUpLeft.value: BlendShapes61.EYE_LOOK_UP_LEFT.value,  # 16 -> 4
        BlendShapes52.EyeSquintLeft.value: BlendShapes61.EYE_SQUINT_LEFT.value,  # 18 -> 5
        BlendShapes52.EyeWideLeft.value: BlendShapes61.EYE_WIDE_LEFT.value,  # 20 -> 6

        # Eye movements - Right
        BlendShapes52.EyeBlinkRight.value: BlendShapes61.EYE_BLINK_RIGHT.value,  # 9 -> 7
        BlendShapes52.EyeLookDownRight.value: BlendShapes61.EYE_LOOK_DOWN_RIGHT.value,  # 11 -> 8
        BlendShapes52.EyeLookInRight.value: BlendShapes61.EYE_LOOK_IN_RIGHT.value,  # 13 -> 9
        BlendShapes52.EyeLookOutRight.value: BlendShapes61.EYE_LOOK_OUT_RIGHT.value,  # 15 -> 10
        BlendShapes52.EyeLookUpRight.value: BlendShapes61.EYE_LOOK_UP_RIGHT.value,  # 17 -> 11
        BlendShapes52.EyeSquintRight.value: BlendShapes61.EYE_SQUINT_RIGHT.value,  # 19 -> 12
        BlendShapes52.EyeWideRight.value: BlendShapes61.EYE_WIDE_RIGHT.value,  # 21 -> 13

        # Jaw movements
        BlendShapes52.JawForward.value: BlendShapes61.JAW_FORWARD.value,  # 22 -> 14
        BlendShapes52.JawRight.value: BlendShapes61.JAW_RIGHT.value,  # 25 -> 15
        BlendShapes52.JawLeft.value: BlendShapes61.JAW_LEFT.value,  # 23 -> 16
        BlendShapes52.JawOpen.value: BlendShapes61.JAW_OPEN.value,  # 24 -> 17

        # Mouth movements
        BlendShapes52.MouthClose.value: BlendShapes61.MOUTH_CLOSE.value,  # 26 -> 18
        BlendShapes52.MouthFunnel.value: BlendShapes61.MOUTH_FUNNEL.value,  # 31 -> 19
        BlendShapes52.MouthPucker.value: BlendShapes61.MOUTH_PUCKER.value,  # 37 -> 20
        BlendShapes52.MouthRight.value: BlendShapes61.MOUTH_RIGHT.value,  # 38 -> 21
        BlendShapes52.MouthLeft.value: BlendShapes61.MOUTH_LEFT.value,  # 32 -> 22
        BlendShapes52.MouthSmileLeft.value: BlendShapes61.MOUTH_SMILE_LEFT.value,  # 43 -> 23
        BlendShapes52.MouthSmileRight.value: BlendShapes61.MOUTH_SMILE_RIGHT.value,  # 44 -> 24
        BlendShapes52.MouthFrownLeft.value: BlendShapes61.MOUTH_FROWN_LEFT.value,  # 29 -> 25
        BlendShapes52.MouthFrownRight.value: BlendShapes61.MOUTH_FROWN_RIGHT.value,  # 30 -> 26
        BlendShapes52.MouthDimpleLeft.value: BlendShapes61.MOUTH_DIMPLE_LEFT.value,  # 27 -> 27
        BlendShapes52.MouthDimpleRight.value: BlendShapes61.MOUTH_DIMPLE_RIGHT.value,  # 28 -> 28
        BlendShapes52.MouthStretchLeft.value: BlendShapes61.MOUTH_STRETCH_LEFT.value,  # 45 -> 29
        BlendShapes52.MouthStretchRight.value: BlendShapes61.MOUTH_STRETCH_RIGHT.value,  # 46 -> 30
        BlendShapes52.MouthRollLower.value: BlendShapes61.MOUTH_ROLL_LOWER.value,  # 39 -> 31
        BlendShapes52.MouthRollUpper.value: BlendShapes61.MOUTH_ROLL_UPPER.value,  # 40 -> 32
        BlendShapes52.MouthShrugLower.value: BlendShapes61.MOUTH_SHRUG_LOWER.value,  # 41 -> 33
        BlendShapes52.MouthShrugUpper.value: BlendShapes61.MOUTH_SHRUG_UPPER.value,  # 42 -> 34
        BlendShapes52.MouthPressLeft.value: BlendShapes61.MOUTH_PRESS_LEFT.value,  # 35 -> 35
        BlendShapes52.MouthPressRight.value: BlendShapes61.MOUTH_PRESS_RIGHT.value,  # 36 -> 36
        BlendShapes52.MouthLowerDownLeft.value: BlendShapes61.MOUTH_LOWER_DOWN_LEFT.value,  # 33 -> 37
        BlendShapes52.MouthLowerDownRight.value: BlendShapes61.MOUTH_LOWER_DOWN_RIGHT.value,  # 34 -> 38
        BlendShapes52.MouthUpperUpLeft.value: BlendShapes61.MOUTH_UPPER_UP_LEFT.value,  # 47 -> 39
        BlendShapes52.MouthUpperUpRight.value: BlendShapes61.MOUTH_UPPER_UP_RIGHT.value,  # 48 -> 40

        # Brow and Cheek movements
        BlendShapes52.BrowDownLeft.value: BlendShapes61.BROW_DOWN_LEFT.value,  # 0 -> 41
        BlendShapes52.BrowDownRight.value: BlendShapes61.BROW_DOWN_RIGHT.value,  # 1 -> 42
        BlendShapes52.BrowInnerUp.value: BlendShapes61.BROW_INNER_UP.value,  # 2 -> 43
        BlendShapes52.BrowOuterUpLeft.value: BlendShapes61.BROW_OUTER_UP_LEFT.value,  # 3 -> 44
        BlendShapes52.BrowOuterUpRight.value: BlendShapes61.BROW_OUTER_UP_RIGHT.value,  # 4 -> 45
        BlendShapes52.CheekPuff.value: BlendShapes61.CHEEK_PUFF.value,  # 5 -> 46
        BlendShapes52.CheekSquintLeft.value: BlendShapes61.CHEEK_SQUINT_LEFT.value,  # 6 -> 47
        BlendShapes52.CheekSquintRight.value: BlendShapes61.CHEEK_SQUINT_RIGHT.value,  # 7 -> 48

        # Nose and Tongue
        BlendShapes52.NoseSneerLeft.value: BlendShapes61.NOSE_SNEER_LEFT.value,  # 49 -> 49
        BlendShapes52.NoseSneerRight.value: BlendShapes61.NOSE_SNEER_RIGHT.value,  # 50 -> 50
        BlendShapes52.TongueOut.value: BlendShapes61.TONGUE_OUT.value,  # 51 -> 51
}
   
def map_61_to_52(bs61_index):
    """
    Maps BlendShapes61 indices to BlendShapes52 indices.
    Returns None if the blendshape doesn't exist in BlendShapes52.
    """
    # Create mapping dictionary from BS61 to BS52

    return mapping_61_to_52.get(bs61_index, None)

def map_52_to_61(bs52_index):
    """
    Maps BlendShapes52 indices to BlendShapes61 indices.
    """
    # Create reverse mapping by inverting the 61_to_52 mapping
    # reverse_mapping = {v: k for k, v in {k: v for k, v in mapping_61_to_52.items() if v is not None}.items()}
    # return reverse_mapping.get(bs52_index, None)

    return mapping_52_to_61.get(bs52_index, None)


# Example usage:
"""
# Convert from BS61 to BS52
bs61_index = BlendShapes61.EYE_BLINK_LEFT.value  # 0
bs52_index = map_61_to_52(bs61_index)  # Returns 9

# Convert from BS52 to BS61
bs52_index = BlendShapes52.EyeBlinkLeft.value  # 9
bs61_index = map_52_to_61(bs52_index)  # Returns 0

# Head rotation parameters (only in BS61) will return None in BS52
head_yaw_61 = BlendShapes61.HEAD_YAW.value  # 52
bs52_index = map_61_to_52(head_yaw_61)  # Returns None
"""
